define(function () {
    'use strict';

    function ctrl($scope,$ionicLoading, LocalCacheService, CommonService, WebService,$sce) {
        function init() {
            $scope.user = LocalCacheService.getUser();
            var code = '1104';
            //判断是否已经签署协议
            $ionicLoading.show();
            WebService.getClientEncontract($scope.user.client_id,code).then(function (data) {
                $ionicLoading.hide();
                if(data.length>0){
                    $scope.status = true;
                }else{
                    //根据签名状态获取电子签名协议
                    WebService.getEncontract(code).then(function (data) {
                        $scope.agreement = data;
                        $scope.agreement.econtract_content = $sce.trustAsHtml($scope.agreement.econtract_content);
                        $scope.status = false;
                    });
                }
            });

        }
        $scope.$on('$ionicView.beforeEnter', function () {
            init();
        });
        $scope.submit = function () {
            $ionicLoading.show();
            //电子签名逻辑
            var params = {client_id:$scope.user.client_id,
                econtract_id: $scope.agreement.econtract_id,econtract_name: $scope.agreement.econtract_name,
                econtract_md5: $scope.agreement.econtract_md5};
            WebService.saveBizEcontract(params).then(function(){
                $ionicLoading.hide();
                CommonService.showComplete('../view/template/entreptemplate.html', '返回首页', 'tab.account-index');
            });
        }
    }

    ctrl.$inject = ['$scope', '$ionicLoading','LocalCacheService', 'CommonService', 'WebService','$sce'];
    return ctrl;
});
